package project02.dao;

import java.util.List;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;

import org.slim3.jdo.GenericDao;
import org.slim3.jdo.SelectQuery;

import project02.meta.MessageDataMeta;
import project02.model.MessageData;

public class MessageDataDao extends GenericDao<MessageData> {

    private static final MessageDataMeta m = new MessageDataMeta();

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(MessageDataDao.class.getName());

    public MessageDataDao() {
        super(MessageData.class);
    }


    public MessageDataDao(PersistenceManager pm) {
        super(MessageData.class, pm);
    }

    @Override
    protected SelectQuery<MessageData> from() {
        return new SelectQuery<MessageData>(pm, m.getModelClass());
    }

    public List<MessageData> findAllByUser(String userId) {
        return from().where(m.userId.eq(userId)).orderBy(m.messageId.asc()).getResultList();
    }

    public MessageData findByUserYearMonthDateWorH(String userId, String year, String month, String date, String worH) {
        return from().where(m.userId.eq(userId), m.year.eq(year), m.month.eq(month), m.date.eq(date), m.worh.eq(worH)).getSingleResult();
    }
}
